<!-- 合同模板 - 综合表单页面 -->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage">
    </ex_super_table_page>
    <ex_super_dialog_form ref="formDialog" :title="dialogTitle" v-bind="dialog"
      @afterSubmitSuccess="submitAfter" />
  </div>
</template>
<script>

let moduleName = "label_srm_contract_management_contract_temp"
import superTablePageFunction from '@/mixin/super-table-page-function';
export default {
  title: moduleName,
  components: {},
  mixins: [superTablePageFunction],
  data() {
    return {

      option: {
        //搜索框内容
        search: {
          //搜索框内容，key为搜索字段，label为标签提示
          model: [
            { label: "label_srm_contract_template_name", key: "contractName", },//普通文字输入
            {
              label: "label_srm_contract_template_type", key: "type", type: 'select', enum: 'ContractTemplateTypeEnum',
            },

          ],
        },
        action: [
          {
            label: 'label_new' + moduleName, attrs: { icon: "el-icon-plus" }, click: () => {
              this.dialogTitle = '新增' + moduleName
              this['$refs']['formDialog'].show(null, {setData:true})
            }
          },
        ],

        table: {
          url: "/srm-api/supplier/ContractTemplateRpc/selectPage.json",
          attrs: {},
          model: [
            { key: 'contractCode', label: 'label_srm_contract_template_code', },
            { key: 'contractName', label: 'label_srm_contract_template_name', },
            { key: 'type', label: 'label_srm_contract_management_contract_type', width: 200, formatter: (r, c, v, i) => this.$enumShow(v, 'ContractTemplateTypeEnum') },
            { key: 'status', label: 'label_srm_contract_template_status', width: 150, formatter: (r, c, v, i) => this.$enumShow(v, 'EnabledOrDisabledEnum') },
            { key: 'versionNo', label: 'label_srm_contract_template_version', width: 150, },
            { key: 'gmtModify', label: 'label_srm_contract_template_update_date', width: 160, formatter: (r, c, v, i) => this.$dateFormat(v) },
            { key: 'notes', label: 'label_srm_contract_template_remark', },
          ],
          operate: [
            {
              label: 'label_srm_contract_management_contract_down',
              disabled: (row) => !row.contractAccessory,
              click: (row) => {
                window.open(this.$ex_default_download_url + row.contractAccessory, '_blank')
              }
            },
            {
              label: 'label_edit', click: (row) => {
                this.dialogTitle = '编辑' + moduleName
                this['$refs']['formDialog'].show({ "id": row["id"] }, false)
              }
            },
            {
              label: 'label_delete', type: "confirm-button", url: '/srm-api/supplier/ContractTemplateRpc/remove.json',
              message: 'label_fms_bank_card_confirm_delete', buttonClass: "button_text_danger", confirmButtonType: 'danger',
              params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
            },
          ],
        }
        ,

      },

      dialogTitle: '',
      dialogFile: null,
      dialog: {
        submitUrl: '/srm-api/supplier/ContractTemplateRpc/saveUpdate.json',
        submitDataHandle: (data) => {
          if (this.dialogFile) {
            data.contractAccessory = this.dialogFile.filePath
          } else {
            data.contractAccessory = null
          }
          return data
        },
        detailUrl: '/srm-api/supplier/ContractTemplateRpc/detail.json',
        detailDataHandle: (data) => {

          if (data.contractAccessory) data.contractAccessoryFile = [{
            filePath: res.data.contractAccessory,
            fileName: "文件链接.link",
          }]
          return data
        },
        form: {
          //弹窗表单设置，设置方式与搜索框对象一致。
          model: [
            { header: "label_srm_contract_management_basic_info", },
            { key: 'contractCode', label: 'label_srm_contract_template_code', maxlength: 40, 'show-word-limit': true, },
            { key: 'contractName', label: 'label_srm_contract_template_name', maxlength: 40, 'show-word-limit': true, },
            { key: 'type', label: 'label_srm_contract_template_type', type: 'select', enum: 'ContractTemplateTypeEnum' },
            { key: 'status', label: 'label_srm_contract_template_status', type: 'select', enum: 'EnabledOrDisabledEnum' },
            { key: 'versionNo', label: 'label_srm_contract_template_version', maxlength: 10, 'show-word-limit': true, },
            { key: 'notes', label: 'label_srm_contract_template_remark', maxlength: 50, 'show-word-limit': true, attrs: { type: 'textarea' } },
            {
              key: 'contractAccessoryFile', label: 'label_srm_contract_template_file', type: 'upload-file',
              limitUploadHide: true, accept: '.doc,.docx,.pdf', maxSize: 5,
              on: { input: (filelist) => this.dialogFile = _.head(filelist) },
            },
          ],
          rules: {
            'contractCode': [{ required: true, message: '请输入合同代码', trigger: 'change' }],
            'contractName': [{ required: true, message: '请输入合同名称', trigger: 'change' }],
            'type': [{ required: true, message: '请输入合同类型', trigger: 'change' }],
            'status': [{ required: true, message: '请输入状态', trigger: 'change' }],
            'versionNo': [{ required: true, message: '请输入版本号', trigger: 'change' }],
            'contractAccessoryFile': [{ required: true, message: '请上传附件', trigger: 'change' }],
          },
        }
      },
    };
  },
  methods: {
    submitAfter(){
      this.reload()
      this.$refreshStoreCommonDataGroup('/srm-api/supplier/ContractTemplateRpc/getContractTemplateDict.json')
    },
  }
};

</script>
<style>

</style>
